<template>
  <div class="cgjhadd">
    <el-form ref="form" :model="form" :rules="rules" label-width="20%">
      <div class="contain">
        <div class="left">
          <el-collapse v-model="activeNames">
            <el-collapse-item title="申请信息" name="1" id="shenqing">
              <div class="form-box">
                <!-- <el-form-item label="申请类型" prop="recordType">
          <el-select
          :disabled="isrecord"
            clearable
            v-model="form.recordType"
            placeholder="请选择申请类型"
          >
            <el-option
              v-for="item in applyType"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
                <el-form-item label="申请人" prop="userName">
                  <el-input
                    :disabled="isrecord"
                    v-model="form.userName"
                    placeholder="请输入申请人"
                  />
                </el-form-item>
                <!--<el-form-item label="部门" prop="deptName">-->
                  <!--<el-input-->
                    <!--:disabled="isrecord"-->
                    <!--v-model="form.deptName"-->
                    <!--placeholder="请输入部门"-->
                  <!--/>-->
                <!--</el-form-item>-->
                <el-form-item v-if="false" label="物资类别" prop="category">
                  <el-select
                    v-model="form.category"
                    :disabled="isrecord"
                    placeholder="请选择物资类别"
                  >
                    <el-option
                      v-for="item in materialCategoryList"
                      :key="item.dictValue"
                      :label="item.dictLabel"
                      :value="item.dictValue"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="仓库" prop="warehouseId">
                  <el-select
                    @change="getHouse"
                    v-model="form.warehouseId"
                    :disabled="isrecord"
                    placeholder="请选择仓库"
                  >
                    <el-option
                      v-for="item in maWarehouseList"
                      :key="item.id"
                      :label="item.warehouse"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="用途" prop="use1">
                  <el-select
                    v-model="form.use1"
                    :disabled="isrecord"
                    placeholder="请选择用途"
                  >
                    <el-option
                      v-for="item in useTypes"
                      :key="item.dictValue"
                      :label="item.dictLabel"
                      :value="item.dictValue"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="用于" prop="usePark">
                  <el-select :disabled="isrecord" v-model="form.usePark" placeholder="请选择园区">
                    <el-option v-for="item in buiParkList" :key="item.id" :label="item.parkName" :value="item.parkName">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="入库时间" prop="operateTime" v-if = "maWarehouseType == '1'">
                  <el-date-picker :disabled="isrecord" clearable size="small"
                                  v-model="form.operateTime"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="选择出入库日期">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="出库时间" prop="operateTime" v-if = "maWarehouseType == '0'">
                  <el-date-picker :disabled="isrecord" clearable size="small"
                                  v-model="form.operateTime"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="选择出库日期">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="盘库时间" prop="operateTime" v-if = "maWarehouseType == '2'">
                  <el-date-picker :disabled="isrecord" clearable size="small"
                                  v-model="form.operateTime"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="选择盘库日期">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="是否出库" prop="isOut" v-if = "maWarehouseType == '1' && !isrecord">
                  <el-select :disabled="isrecord" v-model="form.isOut" placeholder="是否快速出库">
                    <el-option v-for="item in options"
                               :key="item.value" :label="item.lable" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                  <el-input
                    :disabled="isrecord"
                    v-model="form.remark"
                    type="textarea"
                    placeholder="请输入内容"
                  />
                </el-form-item>
              </div>
            </el-collapse-item>
            <el-collapse-item title="物资清单" name="3" id="dianjian">
              <div class="form-box1">
                <el-button
                  :disabled="isrecord"
                  type="primary"
                  @click="addDevice('buiRoomList')"
                  icon="el-icon-plus"
                  size="mini"
                  >选择</el-button
                >
                 <el-button
                   :disabled="isrecord"
                  type="primary"
                  icon="el-icon-plus"
                  size="mini"
                  v-if="maWarehouseType == '1' || maWarehouseType == '2'"
                  @click="canceladd(typeFee)"
                  >新 增</el-button
                >
                <el-table
                  :disabled="isrecord"
                  :data="buiRoomListSelect"
                  ref="buiRoomListSelect"
                >
                  <el-table-column
                    label="物资名称"
                    align="center"
                    prop="materialName"
                  >
                    <template slot-scope="scope">
                      <div class="scope_div">
                        <span class="scope_bt">*</span>
                        <el-input
                          :disabled="!scope.row.ifDisabled"
                          v-model="scope.row.materialName"
                        ></el-input>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="物资类别"
                    align="center"
                    prop="category"
                  >
                    <template slot-scope="scope">
                      <div class="scope_div">
                        <span class="scope_bt">*</span>
                        <el-cascader v-model="scope.row.category" :disabled="!scope.row.ifDisabled" filterable :options="sysBmTypeList" :props="propsBm" :show-all-levels="false" @change="treeSelectFn"></el-cascader>
                      </div>
                    </template>
                  </el-table-column>
                  <!--<el-table-column-->
                    <!--label="物资编码"-->
                    <!--align="center"-->
                    <!--prop="materialNum"-->
                  <!--&gt;-->
                    <!--<template slot-scope="scope">-->
                      <!--<el-input-->
                      <!--disabled-->
                        <!--v-model="scope.row.materialNum"-->
                      <!--&gt;</el-input>-->
                    <!--</template>-->
                  <!--</el-table-column>-->

                  <!--<el-table-column-->
                    <!--label="物资类别"-->
                    <!--align="center"-->
                    <!--prop="category"-->
                  <!--&gt;-->
                    <!--<template slot-scope="scope">-->
                      <!--<el-select-->
                        <!--v-model="scope.row.category"-->
                        <!--:disabled="!scope.row.ifDisabled"-->
                        <!--placeholder="请选择物资类别"-->
                      <!--&gt;-->
                        <!--<el-option-->
                          <!--v-for="item in materialCategoryList"-->
                          <!--:key="item.dictValue"-->
                          <!--:label="item.dictLabel"-->
                          <!--:value="item.dictValue"-->
                        <!--&gt;-->
                        <!--</el-option>-->
                      <!--</el-select>-->
                    <!--</template>-->
                  <!--</el-table-column>-->
                  <el-table-column
                    label="规格型号"
                    align="center"
                    prop="standards"
                  >
                    <template slot-scope="scope">

                      <el-input
                        :disabled="!scope.row.ifDisabled"
                        v-model="scope.row.standards"
                      ></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column label="单位" align="center" prop="unit">
                    <template slot-scope="scope">

                      <div class="scope_div">
                        <span class="scope_bt">*</span>
                      <el-select
                        v-model="scope.row.unit"
                        :disabled="!scope.row.ifDisabled"
                        placeholder="请选择单位"
                      >
                        <el-option
                          v-for="item in unitTypeList"
                          :key="item.dictValue"
                          :label="item.dictLabel"
                          :value="item.dictValue"
                        >
                        </el-option>
                      </el-select>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :label="maWarelabel"
                    align="center"
                    prop="quantity"
                  >
                    <template slot-scope="scope">
                      <el-input
                        :disabled="isrecord"
                        :min="0"
                        :max="scope.row.oldQuantity"
                        v-model.number="scope.row.quantity"
                        type="number"
                      ></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="库存数量"
                    align="center"
                    prop="oldQuantity"
                    v-if="maWarehouseType == '2'"
                  >
                    <template slot-scope="scope">
                      <el-input
                        disabled
                        :min="0"
                        v-model.number="scope.row.oldQuantity"
                        type="number"
                      ></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="单价（元）"
                    align="center"
                    prop="unitPrice"
                  >
                    <template slot-scope="scope">

                      <div class="scope_div">
                        <span class="scope_bt">*</span>
                        <el-input
                          :disabled="isrecord"
                          :min="0"
                          v-model.number="scope.row.unitPrice"
                          type="number"
                        ></el-input>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="总金额（元）"
                    align="center"
                    prop="totalPrice"
                  >
                    <template slot-scope="scope">
                      <span>{{
                        scope.row.unitPrice * scope.row.quantity
                      }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                      <el-button
                        :disabled="isrecord"
                        size="mini"
                        type="text"
                        @click="delDevice('buiRoomList', scope.$index)"
                        >删除</el-button
                      >
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-collapse-item>
          </el-collapse>
        </div>
        <div class="right">
          <div class="my-steps-box">
            <div
              :class="['step-item', stepSelect == index ? 'step-active' : '']"
              v-for="(item, index) in step"
              :key="index"
            >
              <div class="top-title" @click="jump(item.to, index)">
                <div class="cricle"></div>
                <span class="text">{{ item.text }}</span>
              </div>
              <div class="line"></div>
            </div>
          </div>
        </div>
      </div>
      <div class="big-foot-fixed">
        <el-button type="primary" v-if="!maWarehouseId" @click="submitForm"
          >提交</el-button
        >
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-form>
    <!-- 添加设备 -->
    <el-dialog :title="title" :visible.sync="dialogdeviceVisible">
      <div v-if="typeFee === 'buiRoomList'">
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          label-width="68px"
        >
          <el-form-item label="物资名称" prop="materialName">
            <el-input
              v-model="queryParams.materialName"
              placeholder="请输入物资名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="物资编码" prop="materialNum">
            <el-input
              v-model="queryParams.materialNum"
              placeholder="请输入物资编码"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>

        <el-table
          key="buiRoomList"
          ref="buiRoomListRef"
          :data="buiRoomList"
          class="device-style"
          v-loading="loading"
          max-height="250"
          :row-key="getRowKey"
          @selection-change="handleDevice"
        >
          <el-table-column
            v-if="typeFee === 'buiRoomList'"
            type="selection"
            :reserve-selection="true"
            width="55"
            align="center"
          />

          <el-table-column
            label="物资名称"
            align="center"
            prop="materialName"
          />
          <el-table-column label="物资编码" align="center" prop="materialNum" />
          <el-table-column label="规格型号" align="center" prop="standards" />
          <el-table-column label="物资类别" align="center" prop="categoryName">
            <!--<template slot-scope="scope">-->
              <!--<div v-for="(item, index) in materialCategoryList" :key="index">-->
                <!--<span v-if="scope.row.category == item.dictValue">{{-->
                  <!--item.dictLabel-->
                <!--}}</span>-->
              <!--</div>-->
            <!--</template>-->
          </el-table-column>
          <el-table-column label="单位" align="center" prop="unit">
            <template slot-scope="scope">
              <div v-for="(item, index) in unitTypeList" :key="index">
                <span v-if="scope.row.unit == item.dictValue">{{
                  item.dictLabel
                }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column v-if="maWarehouseType == '0'" label="数量" align="center" prop="quantity" />
          <el-table-column label="单价（元）" align="center" prop="unitPrice" />
        </el-table>

        <pagination
          v-show="buiRoomListTotal > 0"
          :total="buiRoomListTotal"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getmaMaterial"
        />
      </div>
      <span slot="footer" class="dialog-footer">

        <el-button @click="cancelDevice(typeFee)">取 消</el-button>
        <el-button type="primary" @click="submitDevice(typeFee)"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { listMaWarehouse } from "@/api/smartParks/property/propertyItemsAdd";
import {
  addmaInOutRecord,
  getmaInOutRecord,
} from "@/api/smartParks/property/propertyItems";
import { listSysBmGoods } from"@/api/system/sysBmGoods.js"
import { listZsCustomer } from "@/api/smartParks/merchants/merchantsCustomer";
import Treeselect from "@riophae/vue-treeselect";
import { listData } from "@/api/system/dict/data"; //字典接口
import { listBuiPark } from "@/api/parkAssets/enterCommunity";
import { listUser } from "@/api/system/user";
import { listByWarehouse } from "@/api/smartParks/property/propertySupplies";
import { listMaMaterial} from "@/api/smartParks/property/maMaterial";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "PropertyItemsAdd",
  components: {
    Treeselect,
  },
  data() {
    return {
      activeNames: ["1", "2", "3", "4", "5"],
      options: [{lable:'否',value:'0'},{lable:'是',value:'1'}],
      step: [
        {
          to: "shenqing",
          text: "申请信息",
        },
        {
          to: "dianjian",
          text: "物资清单",
        },
      ],
      stepSelect: 0,
      // 表单参数
      form: {
        recordType: "",
        userId: "",
        category: "",
        warehouseId: "",
        operateTime: new Date(),
        remark: "",
        isOut:"0",
      },
      zsCustomerList: [], //或缺企业
      buiParkList: [],
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "申请人不能为空", trigger: "change" },
        ],
        warehouseId: [
          { required: true, message: "仓库不能为空", trigger: "blur" },
        ],
        // deptName: [
        //   { required: true, message: "申请部门不能为空", trigger: "blur" },
        // ],
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        houseId: "",
        materialName: "",
        materialNum: "",
      },
      dialogdeviceVisible: false, //房源
      loading: false,
      buiRoomList: [], //房源列表
      buiRoomListTotal: 0,
      buiRoomListSelectTem: [], //选择的
      buiRoomListSelect: [], //确定的
      title: "", //谈框标题
      typeFee: "", //那种费用
      applyType: [],
      materialCategoryList: [],
      userList: [],
      maWarehouseList: [],
      useTypes:[],
      isrecord: false,
      maWarehouseType: "",
      maWarehouseId: "",
      maWarelabel: "",
      unitTypeList: [],
      sysBmTypeList:[],
      propsBm:{
        label:'name',
        value:'bmId',
        children:'children'
      }
    };
  },
  watch: {
    "form.warehouseId": function (newval, oldVal) {
      this.form.warehouseId = newval;
      if (!this.isrecord) {
        this.buiRoomListSelectTem == [];
        // this.buiRoomListSelect = [];
      }
    },
  },
  beforeRouteEnter(to, from, next) {
    if (to.query.type == "0") {
      to.meta.title = "物资出库";
    } else if (to.query.type == "1") {
      to.meta.title = "物资入库";
    } else if (to.query.type == "2") {
      to.meta.title = "物资盘库";
    }
    if (to.query.id) {
      to.meta.title = "物资详情";
    }
    next();
  },
  beforeRouteLeave(to, from, next) {
    this.$store.dispatch("tagsView/delView", this.$route);
    next();
  },
  created() {
    this.maWarehouseId = this.$route.query.id;
    this.maWarehouseType = this.$route.query.type;
    console.log(this.maWarehouseType);
    if (this.maWarehouseType == "0") {
      this.form.recordType = "1";
      this.maWarelabel = "出库数量";
    } else if (this.maWarehouseType == "1") {
      this.form.recordType = "0";
      this.maWarelabel = "入库数量";
    } else if (this.maWarehouseType == "2") {
      this.form.recordType = "2";
      this.maWarelabel = "盘库数量";
    }
    this.getdictDataList();
    this.getmaintainList(); //列表
    this.getList(); //房源
    this.getParkList();
    this.getbmTree()
    if (this.maWarehouseId) {
      this.getmaInOutRecord();
      this.isrecord = true;
    } else {
      this.isrecord = false;
    }
  },
  methods: {
    getParkList(){
      listBuiPark().then((response) => {
        this.buiParkList = response.rows;
      });
    },
    getmaInOutRecord() {
      getmaInOutRecord(this.maWarehouseId).then((response) => {
        const data = response.data;
        this.buiRoomListSelect = data.maMaterialList;

        console.log(
          this.buiRoomListSelect,
          "------------",
          data.maMaterialList
        );
        this.form = data;
      });
    },
    getType() {
      listData({ dictType: "material_apply_type" }).then((response) => {
        this.applyType = response.rows;
      });
      listData({ dictType: "unit_type" }).then((response) => {
        this.unitTypeList = response.rows;
      });
      listData({ dictType: "out_use_type" }).then((response) => {
        this.useTypes = response.rows;
      });
    },
    /** 查询物资类型列表 */
    getdictDataList() {
      listData({ dictType: "material_category" }).then((response) => {
        this.materialCategoryList = response.rows;
      });
    },
    getUser() {
      listUser().then((response) => {
        this.userList = response.rows;
      });
    },
    getMaWarehouse() {
      listMaWarehouse().then((response) => {
        this.maWarehouseList = response.rows;
      });
    },
    /** 查询物品出入管理列表 */
    jump(domId, index) {
      this.stepSelect = index;
      //页面滚动了的距离
      let height =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      let dom = document.getElementById(domId);
      // let domHeight = dom.offsetTop + 60;
      let domHeight = dom.offsetTop - 104;
      //滚动距离计算
      var S = Number(height) - Number(domHeight);
      //判断上滚还是下滚
      if (S < 0) {
        //下滚
        S = Math.abs(S);
        window.scrollBy({
          top: S,
          behavior: "smooth",
        });
      } else if (S == 0) {
        //不滚
        window.scrollBy({
          top: 0,
          behavior: "smooth",
        });
      } else {
        //上滚
        S = -S;
        window.scrollBy({
          top: S,
          behavior: "smooth",
        });
      }
    },

    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.enterpriseType,
        children: node.children,
      };
    },
    // 表单重置
    reset() {
      this.form = {
        recordType: "",
        userId: "",
        category: "",
        warehouseId: "",
        remark: "",
      };
      this.buiRoomListSelect = [];
      this.resetForm("form");
    },
    // 取消按钮
    cancel() {
      this.$store.dispatch("tagsView/delView", this.$route);
      this.$router.go(-1);
    },

    //获取列表
    getmaintainList() {
      //选择企业
      listZsCustomer().then((response) => {
        this.zsCustomerList = response.rows;
      });
    },
    getList() {
      this.getType();
      this.getdictDataList();
      this.getUser();
      this.getMaWarehouse();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getmaMaterial();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    getmaMaterial() {
      if (!this.maWarehouseType) {
        this.queryParams.houseId = "";
      }
      //todo buiRoomList
      if(this.form.recordType == "0"){
        listMaMaterial(this.queryParams).then((response) =>{
          this.buiRoomList = response.rows;
          this.buiRoomListTotal = Number(response.total);
          this.loading = false;
        })
      }else{
        listByWarehouse(this.queryParams).then((response) => {
          // response.rows.forEach((item) => {
          //   this.unitTypeList.forEach((itemType) => {
          //     if (itemType.dictValue == item.unit) {
          //       item.unitName = itemType.dictLabel;
          //     }
          //   });
          // });
          this.buiRoomList = response.rows;
          this.buiRoomListTotal = Number(response.total);
          this.loading = false;
        });
      }
    },
    addDevice(param) {
      if (this.form.warehouseId == "" && this.form.recordType != "0") {
        this.msgSuccess("请选择仓库");
      } else {
        this.queryParams.houseId = this.form.warehouseId;
        this.queryParams.category = this.form.category;
        this.getmaMaterial();
        this.dialogdeviceVisible = true;
        this.typeFee = param;
        if (this.typeFee === "buiRoomList") {
          this.title = "选择物资";
          if (this.buiRoomListSelect.length > 0) {
            this.$refs.buiRoomListRef.clearSelection();
            this.$nextTick(() => {
              this.buiRoomListSelect.forEach((row) => {
                if (row.id) {
                  this.$refs.buiRoomListRef.toggleRowSelection(
                    this.buiRoomList.find((item) => {
                      return row.id === item.id;
                    }),
                    true
                  );
                } else {
                }
              });
            });
          } else {
            this.$nextTick(() => {
              this.$refs.buiRoomListRef.clearSelection();
            });
          }
        }
      }
    },
    unique(arr) {
      return Array.from(new Set(arr));
    },
    //确定
    submitDevice() {
      this.dialogdeviceVisible = false;
      if (this.typeFee === "buiRoomList") {
        const newArr = [];
        const oldArr = [];
        const oldArr1 = [];
        if (this.buiRoomListSelectTem.length > 0) {
          for (var i = 0; i < this.buiRoomListSelectTem.length; i++) {
            var bl = true;
            for (var j = 0; j < this.buiRoomListSelect.length; j++) {
              if (!this.buiRoomListSelect[j].id) {
                oldArr.push(this.buiRoomListSelect[j]);
              }
              if (this.buiRoomListSelectTem[i] === this.buiRoomListSelect[j]) {
                bl = false;
                break;
              }
            }
            if (bl) {
              newArr.push(this.buiRoomListSelectTem[i]);
            }
          }
          for (var i = 0; i < oldArr.length; i++) {
            if (oldArr1.indexOf(oldArr[i]) === -1) {
              oldArr1.push(oldArr[i]);
            }
          }
          this.buiRoomListSelect = [...newArr, ...oldArr1];
        } else {
          this.buiRoomListSelect = JSON.parse(
            JSON.stringify(this.buiRoomListSelectTem)
          );
        }
        this.buiRoomListSelect.filter((item) => {
          item.oldQuantity = item.quantity;
          item.quantity = 0;
        });
      }
    },
    // 添加物资
    canceladd() {
      this.buiRoomListSelect.push({
        materialName: "",
        materialNum:'',
        category: "",
        standards: "",
        unit: "",
        unitPrice: "",
        quantity: "",
        ifDisabled: true,
        id: "",
      });
      this.dialogdeviceVisible = false;
    },
    getRowKey(row) {
      return row.id;
    },
    // //选择物资
    handleDevice(val) {
      if (this.typeFee === "buiRoomList") {
        this.buiRoomListSelectTem = val;
      }
    },

    delDevice(param, index) {
      if (param === "buiRoomList") {
        this.buiRoomListSelect.splice(index, 1);
      }
    },

    cancelDevice() {
      this.dialogdeviceVisible = false;
    },
    //选择办公费用
    handleOffice() {},
    /** 提交按钮 */
    submitForm: function () {
      if (this.isrecord) {
        this.returntomenu();
      } else {
        this.$refs["form"].validate((valid) => {
          if (valid) {
            const bmData = JSON.parse(JSON.stringify(this.buiRoomListSelect))
            let isTrue=true
            bmData.filter(item=>{
              if (!item.id){
                if (item.category=='' || item.unitPrice=='' || item.unit=='' || item.materialName=='') {
                  isTrue=false
                  this.msgError("请填写必填项");
                }else{
                  isTrue=true
                  item.category=item.category[1]
                }
              }
            })
            if (isTrue) {
              this.form.maMaterialList = bmData;
              let data = JSON.parse(JSON.stringify(this.form));
              addmaInOutRecord(data).then((response) => {
                if (response.code === 200) {
                  this.msgSuccess("新增成功");
                  this.reset();
                  this.returntomenu();
                }
              });
            }
          }
        });
      }
    },
    getHouse(row) {
      this.form.warehouseId = row;
    },
    numberChange(val, index) {
      let integer = /^(-|\+)?\d+$/; //输入整数(包括0)的正则，解决不能输入负号问题
    },
    /** 转换编码配置数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.bmId,
        label: node.name,
        children: node.children
      };
    },
    /** 查询编码配置下拉树结构 */
    getbmTree() {
      listSysBmGoods().then(response => {
       this.sysBmTypeList=(this.toTree(response.data))
      });
    },
    toTree(data){
      let result = []
      if (!Array.isArray(data)) {
        return result
      }
      data.forEach(item => {
        delete item.children;
      });
      let map = {};
      data.forEach(item => {
        map[item.bmId] = item;
      });
      data.forEach(item => {
        let parent = map[item.parentId];
        if (parent) {
          (parent.children || (parent.children = [])).push(item);
        } else {
          result.push(item);
        }
      });
      result.forEach(function(item,index,arr){
        if(item.children != null){
          item.children.forEach(itm=>{
            if(itm.children != null){
              delete itm.children;
            }
          })
        }
      })

      return result;
    },
    treeSelectFn(node){
      console.log(node);
      return
      if (node.bmId==0){
        this.form.lv=1
        this.form.parentId=0
      }else {
        this.form.parentId=node.bmId
        this.form.lv=node.lv+1
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.scope_div{
  display: flex;

  .scope_bt{
    color: red;
    margin-right: 5px;
    font-weight: bold;
  }
}
::v-deep .el-select,
.el-date-editor {
  width: 100%;
}
.big-foot-fixed {
  text-align: center;
  padding-bottom: 20px;
}
.cgjhadd {
  overflow: hidden;
  background: #f7f8f8;
  min-height: calc(100vh - 84px);
  height: auto;
  .top {
    height: 40px;
    box-sizing: border-box;
    background: #409eff !important;
    color: #fff;
    padding-left: 20px;
    display: flex;
    align-items: center;
    font-size: 12px;
    justify-content: space-between;
    .submit {
      padding: 3px 10px;
      border-radius: 10px;
      background: #fff;
      color: #409eff;
      cursor: pointer;
      margin-right: 100px;
    }
  }
}

.contain {
  height: auto !important;
  margin: 20px 20px 0px 20px;
  padding-bottom: 20px;
  display: flex;
  .left {
    .text-height {
      height: 80px;
      ::v-deep .el-form-item__content {
        height: 80px;
      }
    }
    .lrAbout {
      display: flex;
      justify-content: space-between;
    }
    width: 90%;
    ::v-deep .el-collapse {
      border-bottom: 0px;
    }
    ::v-deep .el-collapse-item {
      background: #fff;
      font-size: 12px;
      margin-bottom: 20px;

      .el-collapse-item__header,
      .el-collapse-item__wrap {
        background: "";
      }

      .el-collapse-item__header {
        position: relative;
        height: 44px;
        padding-left: 20px;
      }

      .el-collapse-item__header:before {
        position: absolute;
        content: "";
        width: 2px;
        height: 18px;
        background-color: #409eff;
        left: 0;
        top: 13px;
      }

      .el-collapse-item__wrap {
        border-top: 1px solid #e6ebf5;
      }

      .el-collapse-item__content {
        padding-top: 25px;
      }
      .form-box1 {
        width: 100%;
        padding: 0 20px;
        .el-button {
          margin-top: 10px;
        }
        .el-button:first-child {
          margin-top: -10px;
        }
        .el-table {
          margin-top: 10px;
        }
      }
      .form-box {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        padding: 0 20px;

        .el-form-item {
          width: 48%;
        }

        .el-form-item__label {
          font-size: 12px;
          font-weight: normal;
        }

        .el-form-item:nth-child(2n) {
          margin-left: 4%;
        }
      }
    }

    ::v-deep .avatar-uploader .el-upload {
      border: 1px dashed #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
    }

    ::v-deep .avatar-uploader .el-upload:hover {
      border-color: #409eff;
    }

    ::v-deep .avatar-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: 178px;
      height: 178px;
      line-height: 178px;
      text-align: center;
    }

    ::v-deep .avatar {
      width: 178px;
      height: 178px;
      display: block;
    }
  }

  .right {
    width: 10%;

    .my-steps-box {
      font-size: 12px;
      position: fixed;
      right: 30px;
      // top: 104px;
      .step-item {
        margin-bottom: 30px;
        position: relative;
        .top-title {
          display: flex;
          cursor: pointer;
          .cricle {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            margin-right: 5px;
            background: #e8eaec;
            box-sizing: border-box;
            // background: red;
            border: 2px solid #f7f8f8;
          }
        }
        .line {
          position: absolute;
          width: 2px;
          height: 30px;
          top: 12px;
          left: 5px;
          background: #e8eaec;
        }
      }
      .step-item.step-active {
        .cricle {
          border: 2px solid #d5e7f9;
          background-color: #2d8cf0;
        }
        .text {
          color: #2d8cf0;
        }
      }
      .step-item:nth-last-child(1) .line {
        display: none;
      }
    }
  }
}
</style>
